<!DOCTYPE html>
<html lang="en">
<head>
    <!-- start: Meta -->
    <meta charset="utf-8" />
    <title>评分管理</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-responsive.min.css">
    <!--<link rel="stylesheet" href="__STATIC__/bootstrap-table/css/style.min.css">-->
    <!--<link rel="stylesheet" href="__STATIC__/bootstrap-table/css/style-responsive.min.css">-->
    <style>
        .div_box, .div_area{float:left;margin-left:20px;margin-right:20px;}
        .div_area {height:80px;margin-top:5px;width:626px;}
        td{height:40px;}
        .control-num{width:30px;}
        #tr1{ font-weight:600}
        .input-del{width:50%; height:30px; border:0; background-color:#F74020; color:#FFF; text-align:center;}
        select#project {
            width: 150px;
        }
    </style>
    <script language="javascript" type="text/javascript">
        // Example: obj = findObj("image1");
        function findObj(theObj, theDoc)
        {
            var p, i, foundObj;
            if(!theDoc) theDoc = document;
            if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
            {
                theDoc = parent.frames[theObj.substring(p+1)].document;
                theObj = theObj.substring(0,p);
            }
            if(!(foundObj = theDoc[theObj]) && theDoc.all)
                foundObj = theDoc.all[theObj];
            for (i=0; !foundObj && i < theDoc.forms.length; i++)
                foundObj = theDoc.forms[i][theObj];
            for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
                foundObj = findObj(theObj,theDoc.layers[i].document);
            if(!foundObj && document.getElementById)
                foundObj = document.getElementById(theObj);
            return foundObj;
        }


        //添加一行
        function LearnAddSignRow(){ //读取最后一行的行号，存放在LearnTRLastIndex文本框中
            var LearnTRLastIndex = findObj("LearnTRLastIndex",document);
            var rowID = parseInt(LearnTRLastIndex.value);

            var signFrame = findObj("LearnInfoItem",document);
//添加行

            var newTR = signFrame.insertRow(signFrame.rows.length);

            newTR.id = "LearnItem" + rowID;


//添加列:起讫时间
            var newNameTD=newTR.insertCell(0);
//添加列内容
            newNameTD.innerHTML = rowID+1;

//添加列:毕业院校
            var newNameTD=newTR.insertCell(1);
//添加列内容
            newNameTD.innerHTML = "<input name='score" + rowID + "' id='score" + rowID + "' type='text' class='control-label' />";

//添加列:所学专业
            var newEmailTD=newTR.insertCell(2);
//添加列内容
            newEmailTD.innerHTML = "<input name='low_score" + rowID + "' id='low_score" + rowID + "' type='text' class='control-label' />";

//添加列:学制
            var newTelTD=newTR.insertCell(3);
//添加列内容
            newTelTD.innerHTML = "<input name='high_score" + rowID + "' id='high_score" + rowID + "' type='text' class='control-label' />";




//添加列:删除按钮
            var newDeleteTD=newTR.insertCell(4);
//读取上一行的删除按钮
            var newTRTo =document.getElementById("LearnInfoItem").rows[rowID+1].cells[4];
//添加列内容
            if(rowID>1){
                newDeleteTD.innerHTML = "<div align='center'><input id='txtDel" + rowID + "' style='width: 50px' type='button' value='删除' onclick=\"LearnDeleteRow('LearnItem" + rowID + "')\" class='input-del' /></div>";
                newTRTo.innerHTML = "<div align='center'></div>";
            }else{
                newDeleteTD.innerHTML = "<div align='center'><input id='txtDel" + rowID + "' style='width: 50px' type='button' value='删除' onclick=\"LearnDeleteRow('LearnItem" + rowID + "')\" class='input-del' /></div>";
            }
            //newDeleteTD.innerHTML = "<div align='center'><input id='txtDel" + rowID + "' type='button' value='删除' onclick=\"LearnDeleteRow('LearnItem" + rowID + "')\" class='input-del' /></div>";


//将行号推进下一行
            LearnTRLastIndex.value = (rowID + 1).toString() ;
        }
        //删除指定行
        function LearnDeleteRow(rowid){
            var signFrame = findObj("LearnInfoItem",document);
            var signItem = findObj(rowid,document);

//获取将要删除的行的Index
            var rowIndex = signItem.rowIndex;

//删除指定Index的行
            signFrame.deleteRow(rowIndex);

//添加上一行删除按钮
            var allnum=document.getElementById("LearnTRLastIndex");
            var allvalue=document.getElementById("LearnTRLastIndex").value;
            allnum.value=allvalue-1;
            if(allvalue>2){
                var newTRTo =document.getElementById("LearnInfoItem").rows[allvalue].cells[4];
                newTRTo.innerHTML = "<div align='center'><input id='txtDel" + (allvalue-2) + "' type='button' value='删除' onclick=\"LearnDeleteRow('LearnItem" + (allvalue-2) + "')\" class='input-del' /></div>";
            }
        }
    </script>
</head>
<body>
    <!-- start: Content -->
    <div id="content" class="span10" style='width:100%;'>
        <div class="row-fluid">
            <div class="box span9" style='width:100%;'>
                <div class="box-header">
                    <h2><i class="icon-font"></i><span class="break"></span>评分管理</h2>
                </div>
                <div class="box-content">
                    <form id="myform" method="post" action="" class="form-horizontal" onsubmit="return false"/>
                    <table style="width:60%; text-align:center; margin-left:100px;">
                        <tr>
                            <td align="center"><div  style="float:left;">
                                <span style="float:left;">选择年级</span>
                                <select name="grade_id" class="div_box">
                                    {foreach $grade as $value}
                                        <option value="{$value.id}">{$value.grade_title}</option>
                                    {/foreach}
                                </select>
                            </div>
                                <div style="float:right;" >
                                <span style="float:left;">选择项目</span>
                                    <select name="type_id" id="project" class="div_box">
                                        {foreach $info as $value}
                                            <option value="{$value.id}" style="width: 100px">{$value.title}</option>
                                        {/foreach}
                                    </select>
                            </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div  style="float:left;">
                                <span style="float:left;">选择年份：</span>
                                <input type="text" name="year" value="{$year}" readonly>
                                </div>
                                <div style="float:right;" >
                                <span style="float:left;">选择性别</span>
                                <select name="sex" id="sex" class="div_box">
                                    <option value="1" >男</option>
                                    <option value="2">女</option>
                                </select>
                                </div>
                            </td>
                        </tr>

                    </table>
                    <fieldset>
                        <table cellpadding="0" cellspacing="0" border="1" style="width:90%; text-align:center; margin-left:50px;"  id="LearnInfoItem">
                            <tr >
                                <td colspan="5" style="height:30px;" ><div class="box-header">
                                    <h2> 成绩评分标准表</h2>
                                </div>  </td>
                            </tr>
                            <tr id="tr1">
                                <td class="tdStyle2">排列 </td>

                                <td class="tdStyle2">分值</td>

                                <td class="tdStyle2">起始数值</td>

                                <td class="tdStyle2">结束数值</td>

                                <td class="tdStyle2">
                                    <input type="button" name="LearnAdd" value="添加" onclick="LearnAddSignRow()" />
                                    <input name='LearnTRLastIndex' type='hidden' id='LearnTRLastIndex' value="1" />
                                </td>

                            </tr>
                            <tr id="LearnItem0">
                                <td>1</td>
                                <td><input name="score0" id="score0" type="text" class="control-label"></td>
                                <td><input name="low_score0" id="low_score0" type="text" class="control-label"></td>
                                <td><input name="high_score0" id="high_score0" type="text" class="control-label"></td>
                                <td> </td></tr>
                        </table>
                        <div class="control-group ">
                            <label class="control-label" for="textarea2"></label>

                        </div>
                    </fieldset>
                </div>
            </div>
        </div>
    </div>
    <div class="control-group ">
        <div class= "form-actions" style="width:50px;margin: 0 auto">
            <button id="sub" class= "btn btn-primary"> 保存 </button>
        </div>
    </div>
</body>
<script>
    $("#sub").click(function () {
        $.ajax({
            type:'POST',
            url:'/constitution_project/insert',
            data:$("#myform").serialize(),
            beforeSend: function(obj){
                index = layer.msg('添加中请稍后', {
                    icon: 16
                    ,shade: 0.01
                    ,time:1000000
                });
            },
            success:function(res){
                if(res.code){
                    layer.closeAll();
                    layer.msg(res.msg,{icon:1,time:2000},function () {

                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.window.location.reload();
                    });
                }else{
                    layer.closeAll();
                    layer.msg(res.msg,{icon:5,time:2000});
                }
            }
        })
    })
</script>
<script>
    layui.use(['layer'],function () {
        
    })
</script>
</html>